home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / tsfaqp34.zip / FAQPAS.TXT next >
Internet Message Format  |  1996-09-14  |  72KB

  1. From ts@uwasa.fi Sat Sep 14 00:00:00 1996
  2. Subject: FAQPAS.TXT contents
  3.  
  4.                              Copyright (c) 1993-1996 by Timo Salmi
  5.                                                All rights reserved
  6.  
  7. FAQPAS.TXT Frequently (and not so frequently) asked Turbo Pascal
  8. questions with Timo's answers. The items are in no particular order.
  9.  
  10. You are free to quote brief passages from this file provided you
  11. clearly indicate the source with a proper acknowledgment.
  12.  
  13. Comments and corrections are solicited. But if you wish to have
  14. individual Turbo Pascal consultation, please post your questions to
  15. a suitable Usenet newsgroup like news:comp.lang.pascal.borland. It
  16. is much more efficient than asking me by email. I'd like to help,
  17. but I am very pressed for time. I prefer to pick the questions I
  18. answer from the Usenet news. Thus I can answer publicly at one go if
  19. I happen to have an answer. Besides, newsgroups have a number of
  20. readers who might know a better or an alternative answer. Don't be
  21. discouraged, though, if you get a reply like this from me. I am
  22. always glad to hear from fellow Turbo Pascal users.
  23.  
  24. If you are an experienced Turbo Pascal programmer with Turbo Pascal
  25. material you would like to circulate publicly world-wide, you are
  26. welcome to submit your material to the Garbo MS-DOS archives at the
  27. University of Vaasa. To do that you *FIRST* must *CAREFULLY* read
  28. the uploading instructions and the formal requirements in the file
  29. ftp://garbo.uwasa.fi/pc/UPLOAD.INF. You are also welcome to contact
  30. me by email for these instructions if you are not familiar with
  31. downloading them from the Garbo archives.
  32.  
  33. ....................................................................
  34. Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
  35. Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
  36. Department of Accounting and Business Finance  ; University of Vaasa
  37. ts@uwasa.fi http://uwasa.fi/~ts BBS 961-3170972; FIN-65101,  Finland
  38.  
  39. --------------------------------------------------------------------
  40.  1) How do I disable or capture the break key in Turbo Pascal?
  41.  2) How do I get a printed documentation of my students' TP runs?
  42.  3) What is the code for the weekday of a given date?
  43.  4) Need a program to format Turbo Pascal source code consistently
  44.  5) Can someone give me advice for writing a tsr program?
  45.  6) Why can't I read / write the com ports?
  46.  7) What are interrupts and how to use them in Turbo Pascal?
  47.  8) Should I upgrade my Turbo Pascal version?
  48.  9) How do I execute an MS-DOS command from within a TP program?
  49. 10) How is millisecond timing done?
  50. 11) How can I customize the text characters to my own liking?
  51. 12) How to find the files in a directory and subdirectories?
  52. 13) I need a power function but there is none in Turbo Pascal.
  53. 14) How can I create arrays that are larger than 64 kilobytes?
  54. 15) How can I test that the printer is ready?
  55. 16) How can I clear the keyboard type-ahead buffer?
  56. 17) How can I utilize expanded memory (EMS) in my programs?
  57. 18) How can I obtain the entire command line?
  58. 19) How do I redirect text from printer to file in my TP program?
  59. 20) Turbo Pascal is for wimps. Use standard Pascal or C instead?
  60. 21) How do I turn the cursor off?
  61. 22) How to find all roots of a polynomial?
  62. 23) What is all this talk about "Pascal homework on the net"?
  63. 24) How can I link graphics drivers directly into my executable?
  64. 25) How can I trap a runtime error?
  65. --------------------------------------------------------------------
  66.  
  67. Unless otherwise stated the answers cover versions 4.0, 5.0, 5.5,
  68. 6.0 and 7.0 (real mode). The Q&As are not for Turbo Pascal version 3
  69. or earlier. Objects, TVision, Windows, Delphi, etc are not covered.
  70. (I do not use them myself.)
  71. --------------------------------------------------------------------
  72.  
  73. From ts@uwasa.fi Sat Sep 14 00:00:01 1996
  74. Subject: Disabling or capturing the break key
  75.  
  76. 1. *****
  77.  Q: I don't want the Break key to be able to interrupt my TP
  78. programs. How is this done?
  79.  Q2: I want to be able to capture the Break key in my TP program.
  80. How is this done?
  81.  Q3: How do I detect if a certain key has been pressed? (Often, how
  82. do I detect, for example, if the CursorUp key has been pressed?)
  83.  Q4: How do I detect if a cursor key or a function key has been
  84. pressed?
  85.  
  86.  A: This set of frequently asked questions is basically a case of
  87. RTFM (read the f*ing manual). But this feature is, admittedly, not
  88. very prominently displayed in the Turbo Pascal reference. (As a
  89. general rule we should not use the newsgroups as a replacement for
  90. our possibly missing manuals, but enough of this line.)
  91.    I'll only explain Q and Q2. The other two, Q3 and Q4 should be
  92. evident from the example code.
  93.    There is a CheckBreak variable in the Crt unit, which is true by
  94. default. To turn it off use
  95.      uses Crt;
  96.      :
  97.      CheckBreak := false;
  98.      :
  99. Besides turning off break checking this enables you to capture the
  100. pressing of the break key as you would capture pressing ctrl-c. In
  101. other words you can use e.g.
  102.      :
  103.   procedure TEST;
  104.   var key : char;
  105.   begin
  106.     repeat
  107.       if KeyPressed then
  108.         begin
  109.           key := ReadKey;
  110.           case key of
  111.              #0 : begin
  112.                     key := ReadKey;
  113.                     case key of
  114.                       #59 : write ('F1 ');
  115.                       #72 : write ('CursUp ');   { Detecting these }
  116.                       #75 : write ('CursLf ');   { is often asked! }
  117.                       #77 : write ('CursRg ');
  118.                       #80 : write ('CursDn ');
  119.                       else write ('0 ', ord(key), ' ');
  120.                     end; {case}
  121.                   end;
  122.              #3 : begin    {ctrl-c or break}
  123.                     writeln ('Break');
  124.                     halt(1);
  125.                   end;     { Terminate the program, or whatever }
  126.             #27 : begin
  127.                     write ('<esc> ');
  128.                     exit;  { Exit test, continue program }
  129.                   end;
  130.             else write (key, ' ');
  131.           end; {case}
  132.         end; {if}
  133.     until false;
  134.   end;  (* test *)
  135.      :
  136. IMPORTANT: Don't test the ctrl-break feature just from within the TP
  137. IDE, because it has ctlr-break handler ("interceptor") of its own
  138. and may confuse you into thinking that ctrl-break cannot be
  139. circumvented by the method given above.
  140.   The above example has a double purpose. It also shows the
  141. rudiments how you can detect if a certain key has been pressed. This
  142. enables you to give input without echoing it to the screen, which is
  143. a later FAQ in this collection.
  144.   This is, however, not all there can be to break checking, since
  145. the capturing is possible only at input time. It is also possible to
  146. write a break handler to interrupt a TP program at any time. For
  147. more details see Ohlsen & Stoker, Turbo Pascal Advanced Techniques,
  148. Chapter 7. (For the bibliography, see FAQPASB.TXT in this same FAQ
  149. collection).
  150.  
  151.  A2: This frequent question also elicits one of the most frequent
  152. false answers. It is often suggested erroneously that the relevant
  153. code would be
  154.   uses dos;
  155.   SetCBreak(false);
  156. This is not so. It confuses MS-DOS and TP break checking with each
  157. other. SetCBreak(false) will _*NOT*_ disable the Ctrl-Break key for
  158. your Turbo Pascal program. What it does is "Sets the state of
  159. Ctrl-Break checking in DOS". SetCBreak sets the state of Ctrl+Break
  160. checking in DOS. When off (False), DOS only checks for Ctrl+Break
  161. during I/O to console, printer, or communication devices. When on
  162. (True), checks are made at every system call."
  163.    This item goes to shows how important it is carefully to check
  164. one's code and facts before claiming something.
  165.  
  166.  A3: Using the "CheckBreak := false;" method is not the only
  167. alternative, however. Here is an example code for disabling
  168. Ctrl-Break and Ctrl-C with interrupts
  169.   uses Dos;
  170.   var OldIntr1B : pointer;  { Ctrl-Break address }
  171.       OldIntr23 : pointer;  { Ctrl-C interrupt handler }
  172.       answer    : string;   { For readln test }
  173.   {$F+}
  174.   procedure NewIntr1B (flags,cs,ip,ax,bx,cx,dx,si,di,ds,es,bp : word);
  175.             Interrupt;
  176.   {$F-} begin end;
  177.   {$F+}
  178.   procedure NewIntr23 (flags,cs,ip,ax,bx,cx,dx,si,di,ds,es,bp : word);
  179.             Interrupt;
  180.   {$F-} begin end;
  181.   begin
  182.     GetIntVec ($1B, OldIntr1B);
  183.     SetIntVec ($1B, @NewIntr1B);   { Disable Ctrl-Break }
  184.     GetIntVec ($23, OldIntr23);
  185.     SetIntVec ($23, @NewIntr23);   { Disable Ctrl-C }
  186.     writeln ('Try breaking, disabled');
  187.     readln (answer);
  188.     SetIntVec ($1B, OldIntr1B);    { Enable Ctrl-Break }
  189.     SetIntVec ($23, OldIntr23);    { Enable Ctrl-C }
  190.     writeln ('Try breaking, enabled');
  191.     readln (answer);
  192.     writeln ('Done');
  193.   end.
  194. --------------------------------------------------------------------
  195.  
  196. From ts@uwasa.fi Sat Sep 14 00:00:02 1996
  197. Subject: Directing output also to printer
  198.  
  199. 2. *****
  200.  Q: I want to have a printed documentation of my students' Turbo
  201. Pascal program exercises. How is all input and output directed also
  202. to the printer?
  203.  
  204.  A1: Use a screen capturing program to put everything that comes
  205. onto the screen into a file, and print the file. See FAQPROGS.TXT in
  206. ftp://garbo.uwasa.fi/pc/ts/tsfaqn45.zip (or whatever version number
  207. is the current) for more about these programs. Available by
  208. anonymous FTP or mail server from garbo.uwasa.fi.
  209.  
  210.  A2: See the code in TSPAS.NWS (item: Redirecting writes to the
  211. printer) in the ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip (or whatever
  212. is the current version number) Turbo Pascal units package (70 = 40,
  213. 50, 55, 60, or 70 depending on your TP version). Alternatively use
  214. USECON and USEPRN routines in the TSUNTG unit of the same package.
  215.  
  216.      +------------------------------------------+
  217.      ! To get these and other packages given as !
  218.      !   /dir/subdir/name                       !
  219.      ! see the instructions in PD2ANS.TXT       !
  220.      +------------------------------------------+
  221.  
  222.  A3: But the really elegant solution to the problem of getting a
  223. logfile (or a printed list) of a Turbo Pascal run is to rewrite the
  224. write(ln) and read(ln) device driver functions. In itself writing
  225. such driver redirections is very advanced Turbo Pascal programming,
  226. but when the programming has once been done, the system is extremely
  227. easy to use as many times as you like. It goes like this. The driver
  228. redirections are programmed into a unit (say, tpulog or tpuprn). All
  229. that is needed after that is to include the following uses statement
  230. into the program (the target program) which has to be logged:
  231.       uses TPULOG;    ( or )    uses TPUPRN;
  232. This is all there is to it. Just adding one simple line to the
  233. target program. (If you call any other units, "uses tpulog" must
  234. come AFTER the system units (e.g. Dos), but BEFORE any which you may
  235. define yourself!)
  236.    The reason that I have named two units here instead of just one
  237. in the above example is that the preferred log for the target
  238. program may be a logfile or the printer. The better solution of
  239. these two is to use the logfile option, and then print it. The
  240. reason is simple. If the target program itself prints something,
  241. your printout will look confused.
  242.    The logging also has obvious limitations. It works for standard
  243. input and output (read(ln) and write(ln)) only. 1) It does not
  244. support graphics, in other words it is for the textmode. 2) It does
  245. not support direct (Crt) screen writes. 3) And, naturally it only
  246. shows the input and output that comes to the screen. Not any other
  247. input or output, such as from or to a file. 4) Furthermore, you are
  248. not allowed to reassign input or output. Statements like assign
  249. (output, '') will result in a crash, because the rewritten output
  250. device redirections are invalidated by such statements. 5) The
  251. device on the default drive must not be write protected, since else
  252. the logfile cannot be written to it. 6) It does not work for Turbo
  253. Pascal 4.0. Despite these restrictions, the method is perfectly
  254. suited for logging students' Turbo Pascal escapades.
  255.    It is advisable first to test and run your target program without
  256. "tpulog", so that if you get any strange errors you'll know whether
  257. they are caused by the logging.
  258.    Where to get such a unit. The code can be found in Michael
  259. Tischer (1990), Turbo Pascal Internals, Abacus, Section 4.2. Next a
  260. few of my own tips on this unit Tischer calls Prot. 1) The code is
  261. in incorrect order. The code that is listed on pages 142 - 145 goes
  262. between pages 139 and 140. 2) You can change the logfile name (const
  263. prot_name) to lpt1 for a printed list of the target program run. In
  264. that case it is advisable to include a test for the online status of
  265. the printer within Tischer's unit. 3) I see no reason why the two
  266. lines in Tischer's interface section couldn't be transferred to the
  267. implementation section. Why have any global definitions?  But all in
  268. all, it works like magic!
  269.  
  270.  A4: From: abcscnuk@csunb.csun.edu (Naoto Kimura (ACM))
  271. Subject: Re: Printing a log of students' exercises revisited
  272. To: ts@uwasa.fi
  273. Date: Fri, 2 Nov 90 20:52:03 pdt
  274. [Reproduced with Naoto's kind permission]
  275. By the way, several months ago, I had submitted a file (nktools.zip)
  276. file on SimTel that contains sources to a unit (LOGGER), which
  277. allows logging of I/O going through the standard input and output
  278. files, while still being able to use the program interactively.  I
  279. believe that I also submitted a copy to your site.  It was something
  280. I put together for use by students here at California State
  281. University at Northridge.  The source works equally well in all
  282. presently available versions of Turbo Pascal.
  283. The only requirements are that
  284.  * you place it as one of the last entries in the USES clause.  If
  285.    there is anything that redirects the standard input and output
  286.    file variables, you should put that unit before my unit in the
  287.    USES clause, so that it can see the I/O stream.
  288.  * Don't use the GotoXY and similar screen display control
  289.    procedures in the Crt unit and expect it to come out the same way
  290.    you had it on the display.  Since all my unit does is just
  291.    capture the I/O stream to send it through the normal channels and
  292.    also to the log file, all screen control information is not sent
  293.    to the log file.
  294.  * All I/O you want logged should go through the standard input and
  295.    output file variables.
  296.  * Don't close the standard input and output file variables, because
  297.    it will cause problems.  Basically, as far as I have checked, it
  298.    just causes the logging to stop at that point.
  299. --------------------------------------------------------------------
  300.  
  301. From ts@uwasa.fi Sat Sep 14 00:00:03 1996
  302. Subject: Code to give the weekday of a date
  303.  
  304. 3. *****
  305.  Q: I want code that gives the weekday of the given date.
  306.  
  307.  A1: Here is a source code based on the original code by Anders Roar
  308. Nielsen and postings by Mark Cole, Dr. John Stockton and yours truly
  309. in news:comp.lang.pascal.borland. Only apply on the Gregorian
  310. calendar.
  311.   function WeekDay ( Day, Month, Year : Integer ) : Integer;
  312.     function FirstThursday (Year: Integer) : Integer;
  313.     begin
  314.       FirstThursday := 7 - (1 + (Year-1600) + (Year-1597) div 4
  315.       - (Year-1501) div 100 + (Year-1201) div 400) mod 7;
  316.     end; (* FirstThursday *)
  317.     function DayNumber (Day, Month, Year : Integer) : Integer;
  318.     const DaysBeforeMonth : array [1..12] of Integer =
  319.           (0,31,59,90,120,151,181,212,243,273,304,334);
  320.     begin
  321.       DayNumber := DaysBeforeMonth[Month] + Day + Ord( (Month > 2) and
  322.         (Year mod 4 = 0) and ((Year mod 100 <> 0) or
  323.         (Year mod 400 = 0)) );
  324.     end; (* DayNumber *)
  325.   begin
  326.     WeekDay:=(7+DayNumber(Day,Month,Year)-FirstThursday(Year)+3) mod 7;
  327.   end; (* WeekDay *)
  328.   {}
  329.   function WeekDayString (Day, Month, Year : Integer) : String;
  330.   const DayStr = 'MonTueWedThuFriSatSun';
  331.   begin
  332.     WeekDayString := Copy (DayStr, 3*WeekDay(Day,Month,Year)+1, 3);
  333.   end;
  334.  
  335.  A2: There is a WKDAYFN function in my Turbo Pascal units collection
  336. ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip (or whatever version number
  337. is the latest, and where 70 is 40 50 55 60 and 70) Turbo Pascal
  338. units collection to give the modern weekday based on Zeller's
  339. congruence. Available by anonymous FTP or mail server from
  340. garbo.uwasa.fi. Also you can find a more extensive Julian and
  341. Gregorian weekday algorithm with source code in Dr.Dobb's Journal,
  342. June 1989, p. 148. Furthermore Press & Flannery & al (1986),
  343. Numerical Recipes, Cambridge University Press, present a weekday
  344. code. The Numerical Recipes codes are available as
  345. ftp://garbo.uwasa.fi/pc/turbopas/nrpas13.zip (big, 404k!). If you
  346. wish to know more of calendars see Claus Tondering's calendar FAQ
  347. ftp://garbo.uwasa.fi/pc/doc-net/calfaq.zip.
  348.  
  349.  A3: Some will recommend the following kludge. Store the current
  350. date, change it, and let MS-DOS get you the weekday. Don't use it!
  351. It is a bad suggestion. On top of being sloppy programming, there
  352. are several snags.  The trick works only for years 1980-2079. A
  353. crash the program may leave the clock at a wrong date. And even if
  354. multitasking is rare, in a multitasking environment havoc may result
  355. for the other tasks. And you may have a TSR that requires the
  356. correct date, etc.
  357. --------------------------------------------------------------------
  358.  
  359. From ts@uwasa.fi Sat Sep 14 00:00:04 1996
  360. Subject: Pretty printers (or uniform code)
  361.  
  362. 4. *****
  363.  Q: Where can I find a program that formats my (or my students')
  364. Turbo Pascal code in a consistent matter.
  365.  
  366.  A: What you are asking for is often called "a pretty printer".
  367. TurboPower Software's (the usual disclaimer applies) commercial
  368. Turbo Analyst has a facility for this with many options. There are
  369. also PD and shareware pretty printers, such as
  370.  :
  371.  16830 Nov 28 1989 ftp://garbo.uwasa.fi/pc/turbopas/ppdk50.zip
  372.  ppdk50.zip Pascal Prettypringting Program, tweak, D.Kirschbaum
  373.  :
  374.  10015 Mar 29 1991 ftp://garbo.uwasa.fi/pc/turbopas/ppp.zip
  375.  ppp.zip Pretty Print Pascal, with Turbo Pascal 5+ source, M.Bless
  376.  :
  377.  38021 Nov 5 1994 ftp://garbo.uwasa.fi/pc/turbopas/bp7sb104.zip
  378.  bp7sb104.zip Borland and TP Source Beautifier, crippleware, J.Ferincz
  379.  :
  380.  25100 Jul 4 1992 ftp://garbo.uwasa.fi/pc/turbopas/epb232.zip
  381.  epb232.zip Ed's Pascal Beautifier, E.Lee
  382.  :
  383. and others at garbo.uwasa.fi available by anonymous FTP or mail
  384. server. See ftp://garbo.uwasa.fi/pc/INDEX.ZIP for the list of the
  385. files.
  386. --------------------------------------------------------------------
  387.  
  388. From ts@uwasa.fi Sat Sep 14 00:00:05 1996
  389. Subject: How to write TSR programs
  390.  
  391. 5. *****
  392.  Q: Can someone give me advice for writing a tsr program?
  393.  
  394.  A: Writing a terminate and stay resident program can be considered
  395. advanced programming and is beyond the scope of an electronic
  396. message with limited space. Instead, here are some references to
  397. Turbo Pascal books and papers which have a coverage of the subject.
  398. Stephen O'Brien, Turbo Pascal, The Complete Reference, Chapter 16;
  399. Stephen O'Brien, Turbo Pascal, Advanced Programmer's Guide, Chapter
  400. 6; Michael Tischer, Turbo Pascal Internals, Chapter 11 (a definite
  401. bible of TP programming!); Michael Tischer (1992), PC Intern System
  402. Programming, Chapter 32; Michael Yester, Using Turbo Pascal, Chapter
  403. 19; Kent Pottebaum, "Creating TSR Programs with Turbo Pascal", Dr.
  404. Dobb's Journal, May 1989 and June 1989; Kris Jamsa, Dos Power User's
  405. Guide, pp. 649-; Edward Mitchell (1993), Borland Pascal Developer's
  406. Guide, Section "Writing TSRs", pp. 370-400, with 778 lines of sample
  407. code.
  408.    Also see example code files like
  409. ftp://garbo.uwasa.fi/pc/turboobj/tsrhelp.zip,
  410. ftp://garbo.uwasa.fi/pc/turbopa45/tess-5.zip,
  411. ftp://garbo.uwasa.fi/pc/turbopa45/tsrunit.zip,
  412. ftp://garbo.uwasa.fi/pc/turbopa7/pptsr10.zip,
  413. ftp://garbo.uwasa.fi/pc/turbopa7/tsrsrc35.zip,
  414. ftp://garbo.uwasa.fi/pc/turbopas/deltsr.zip,
  415. ftp://garbo.uwasa.fi/pc/turbopas/tp4_tsr.zip.
  416.    Furthermore, you should see the TSR.SWG examples in the fine SWAG
  417. (SourceWare Archival Group's) collection of TP sources. Available
  418. from the /pc/turbopas directory at Garbo. For the current references
  419. to the SWAG files see ftp://garbo.uwasa.fi/pc/INDEX.ZIP.
  420. --------------------------------------------------------------------
  421.  
  422. From ts@uwasa.fi Sat Sep 14 00:00:06 1996
  423. Subject: Programming com ports
  424.  
  425. 6. *****
  426.  Q: Why can't I read / write the com ports.
  427.  
  428.  A: Com port programming (most often writing telecommunication
  429. programs) is much much more complicated than simply trying to use
  430.   write (com, whatever);
  431.   read  (com, whatever);
  432. This is a very advanced subject (frankly, beyond me), and the best
  433. way to learn is to try to obtain some code to show you how. One
  434. place to look at is Turbo Pascal text-books (I have a long list of
  435. them at garbo.uwasa.fi archives in my collection of Turbo Pascal
  436. units ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip. There also is an
  437. example by David Rind in ftp://garbo.uwasa.fi/pc/pd2/faquote.zip.
  438. Another source is International FidoNet pascal conference at some
  439. bulletin board near you. The conference has had some very good
  440. discussions in it. (No, I don't have them stored for distribution,
  441. nor any further information.) Some files you might wish to look at:
  442. ftp://garbo.uwasa.fi/pc/turbopas/comm_tp5.zip and comtty30.zip.
  443.    Furthermore, you should see the COMM.SWG examples in the fine
  444. SWAG (SourceWare Archival Group's) collection of TP sources.
  445. Available from the /pc/turbopas directory at Garbo. For the current
  446. references to the SWAG files see ftp://garbo.uwasa.fi/pc/INDEX.ZIP.
  447. --------------------------------------------------------------------
  448.  
  449. From ts@uwasa.fi Sat Sep 14 00:00:07 1996
  450. Subject: Primers to interrupt programming
  451.  
  452. 7. *****
  453.  Q: What are interrupts and how to use them in Turbo Pascal?
  454.  
  455.  A: An interrupt is a signal to the processor from a program, a
  456. hardware device, or the processor itself, to suspend temporarily
  457. what the program is doing, and to perform a routine that is stored
  458. in the operating system. There are 256 such interrupt routines, with
  459. many subservices stored in memory at locations, which are given in
  460. the so called interrupt table. Turbo Pascal (somewhat like C) has a
  461. special keyword Intr, and a predefined variable registers (in the
  462. Dos unit) to access these interrupt routines. One way of looking at
  463. them is as Turbo Pascal (complicated lowlevel) subroutines that are
  464. already there ready for you to call.
  465.    A detailed description of interrupt routines is way beyond a
  466. single message with limited space. Instead, I shall give a simple
  467. example, and good references to the subject. (For a somewhat more
  468. comprehensive description of what an interrupt is, see INTERRUP.PRI
  469. in Ralf Brown's ftp://garbo.uwasa.fi/pc/programming/inter51b.zip.)
  470.      :
  471.      uses Dos;
  472.      (* This procedure turns on the border color for CGA and VGA *)
  473.      procedure BORDER (color : byte);
  474.      var regs : registers;  (* Predeclared in the Dos unit *)
  475.      begin
  476.        FillChar (regs, SizeOf(regs), 0);  (* A precaution *)
  477.        regs.ax := $0B00;    (* Service number *)
  478.        regs.bh := $00;      (* Subservice number *)
  479.        regs.bl := color;
  480.        Intr ($10, regs);    (* ROM BIOS video driver interrupt *)
  481.      end;  (* border *)
  482.    If you are new the subject and / or want ideas on the most useful
  483. interrupts in Turbo Pascal programming, Ben Ezzel (1989),
  484. Programming the IBM User Interface Using Turbo Pascal, is definitely
  485. the best reference to look at. There are also many other good
  486. references for a novice interrupt user, such as Jamsa & Nameroff,
  487. Turbo Pascal Programmer's Library.
  488.    If you are a more advanced interrupt user you'll find the
  489. following references very useful. Michael Tischer (1990), Turbo
  490. Pascal Internals; Norton & Wilton (1988), The New Peter Norton
  491. Programmer's guide to the IBM PC & PS/2; Ray Duncan (1988), Advanced
  492. MS-DOS Programming; Terry Dettmann (1989), Dos Programmer's
  493. Reference, Second edition, Que. Furthermore, there is an impressive
  494. list of interrupts collected and maintained by Ralf Brown. His
  495. extensive ftp://garbo.uwasa.fi:/pc/programming/inter51a.zip,
  496. inter51b.zip, inter51c.zip, inter51d.zip, inter51e.zip and
  497. inter51f.zip (or whatever are the current versions when you read
  498. this) is available by anonymous FTP or mail server from
  499. garbo.uwasa.fi. A definite must for an advanced user. Also see the
  500. reference to Brown's and Kyle's book in the bibliography at the end
  501. of this FAQ. There is also a good hypertext advanced programmer's
  502. quick reference ftp://garbo.uwasa.fi/pc/programming/helppc21.zip
  503. which you might find useful.
  504.    One more point for Turbo Pascal users. When Borland upgraded from
  505. version 3 to 4.0 quite a number of tasks that needed to be done
  506. using interrupts (such as getting the current time) were included as
  507. normal TP routines. This means that while definitely useful,
  508. interrupt programming is now relevant only in advanced Turbo Pascal
  509. programming. Turbo Pascal 5.0 introduced a few more, but you can
  510. find some of the missing TP 4.0 routines in the compatibility unit
  511. in my ftp://garbo.uwasa.fi/pc/ts/tspa3540.zip TP units collection.
  512. --------------------------------------------------------------------
  513.  
  514. From ts@uwasa.fi Sat Sep 14 00:00:08 1996
  515. Subject: Borland's Turbo Pascal upgrades
  516.  
  517. 8. *****
  518.  Q: Should I upgrade my Turbo Pascal version?
  519.  
  520.  A1: Depends on what version you are using, and for what purposes.
  521. If you are using version 3, the answer is a definite yes. There are
  522. so many useful additions in the later version, including the concept
  523. of units, and a great number of new useful keywords. The only reason
  524. that I can think of for using TP 3 is that it makes .com files
  525. (which reside in one memory segment only) instead of .exe files. As
  526. an accounting and business finance teacher and researcher I've been
  527. somewhat surprised to see postings stating that some users still
  528. have to program in TP 3.0 because their employer doesn't want to
  529. take the cost of upgrading. I find this cost argument ridiculous.
  530. How about some consideration for cost effectiveness and
  531. productivity?
  532.    If you are currently using version 4.0, the most important point
  533. in considering upgrading is the integrated debugger in the later
  534. versions. It is really good, and useful if you write much code.
  535. There are some minor considerations, as well. Later versions contain
  536. some useful routines which 4.0 does not. I have programmed many of
  537. them to be available also for 4.0 in my units collection
  538. ftp://garbo.uwasa.fi/pc/ts/tspa3540.zip (or whatever is the latest
  539. when you read this). Furthermore, I find somewhat annoying that the
  540. executables will always end up in the default directory.
  541.    If you are currently using version 5.0 the rational reasons for
  542. upgrading are needing objects, and a better overlay manager. I have
  543. also version 5.5 myself, but switched back to version 5.0 after I
  544. had some problems with its linking of object files. (This is a false
  545. statement from me, since it turned out that I had made a mistake
  546. myself. My thanks are due to bj_stedm@gould2.bristol-poly.ac.uk
  547. (Bruce Stedman) for questioning this item). Anyway, I don't use nor
  548. need OOP objects (don't confuse linking object files and object
  549. oriented programming here). One further point for 5.5. It has a
  550. better help function than 5.0, and a few more procedures and
  551. predefined constants. The TP 5.5 help includes examples, which can
  552. be even pasted into your program. This is handy.
  553.    The real snag in upgrading (waiving the reasonable cost) is the
  554. fact that the units of the different versions are incompatible. If
  555. you have a large library of units (as I do) you will have to
  556. recompile the lot. This is something that has caused a fair amount
  557. of justifiable flak against an otherwise excellent product.
  558.    A tip. Don't throw away your Turbo Pascal version 3.0 manual, if
  559. you have one. It is of use if you resort to the Turbo3 and Graph3
  560. compatibility units. They give you access e.g. to turtle graphics.
  561.    At the time of first writing this Turbo Pascal 6.0 version had
  562. just been announced. I didn't have it yet myself, but I had been
  563. (correctly) informed that its units are not compatible with the
  564. earlier versions. I now have Turbo Pascal 6.0, and I must say that
  565. my reactions have been disappointment and frustration. This is
  566. probably partly (but not entirely) my own fault, since Turbo Pascal
  567. seems to be headed from a common programming language into a full
  568. professional's specialized tool, with many features I don't know how
  569. to utilize. The only advancement from my point of view really is the
  570. multiple file editing, but I have long had alternative programs for
  571. that. If I used assembler (I don't) I am sure that I would find
  572. useful TP 6.0's potential to include assembler code as such instead
  573. of having to use the cumbersome Inline procedure of entering the
  574. assembler code.
  575.    There is also a Windows Turbo Pascal, as the latest addition to
  576. the plethora. Since I don't use Windows at all, I have no further
  577. information on it.
  578.    I think a pattern is emerging here. Rather than being different
  579. versions of the same product, the consecutive Turbo Pascals are
  580. really different products for different purposes. Version 3.0 was a
  581. simple programming language. Version 4.0 extended it into a full
  582. scale programming modular platform. Version 5.0 introduced the
  583. debugger. And there an advanced hobbyist's path ended. Version 5.5
  584. introduced object oriented programming, which I'm sure is important
  585. for the initiated, but personally I just don't need it even if I
  586. write a lot of programs. And with the 6.0 we go completely out of
  587. the realm of conventional programming into Turbo Pascal visions.
  588. And Windows Turbo Pascal is for a different platform, altogether.
  589.    I find the new integrated user interface of TP 6.0 awkward in
  590. comparison to what was used in the 4.0, 5.0, and 5.5 versions. The
  591. IDE of TP leaves less free memory than the previous versions.
  592. Furthermore TP 6.0 IDE performs frequent disk accesses which cause
  593. slowdowns  making it virtually unusable from a floppy. And I
  594. wonder why Borland didn't at once go all the way to Windows, because
  595. that is what 6.0 really is. An intermediate, incomplete step in that
  596. direction. This means that we have a 5th upgrade in line with
  597. incompatible units. This is aggravating even for a TP fan, isn't it?
  598.    For information on Turbo Pascal version 7.0 and Borland email
  599. contact numbers see ftp://garbo.uwasa.fi/pc/turbopa7/bp7-info.zip.
  600. Also see ftp://garbo.uwasa.fi/pc/turbspec/bp7bugs2.zip by Duncan
  601. Murdoch. Turbo Pascal 7.0 or more extensively Borland Pascal 7.0 is
  602. a full professional's tool, and far beyond for example my moderate
  603. programming needs. To list only a few of the features are protected
  604. mode programming, handling of large programs, very fast compiling,
  605. and a daunting amount of material elbowing its away on one's disk
  606. space if one ever has the patience to look through it all. I would
  607. use the word "overwhelming". But for a serious programmer this is an
  608. impressive and a very worthwhile tool. One should not be misled
  609. skipping it because of my comments which were written from a
  610. hobbyist's point of view. As a general trend in programs, the
  611. well-known columnist John C. Dvorak calls this increasing product
  612. complexity trend "featurism" in PC Computing, May 1993. But TP 7.0
  613. (7.01) has some important features also from a hobbyist's point of
  614. view. So much so that I have finally succumbed to 7.01 myself. I
  615. particularly like the color coding of the keywords, and the TPX
  616. version enabling compiling very large programs (utilizing extended
  617. memory). A very welcome addition are the new keywords break and
  618. continue to exit or recycle a for, while or a repeat loop are.
  619. Besides they make using the outcast goto statements virtually
  620. unnecessary.
  621.  
  622.  A2: From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch),
  623. Newsgroups: comp.lang.pascal. Included with Duncan's kind
  624. permission. [Duncan is one of the most knowledgeable and useful
  625. contributors to the comp.lang.pascal UseNet newsgroup (later
  626. replaced by comp.lang.pascal.borland for TP)].
  627.    One other reason:  there's a bug in the code generator for 4.0
  628. and 5.0 that makes it handle the Extended (10 byte) real type
  629. poorly.  The code generated makes very poor use of the 8 element
  630. internal stack on the coprocessor, so that expressions with lots of
  631. operands like
  632.   e1+e2+e3+e4+e5+e6+e7+e8+e9
  633. always fail, if all the e's are of type extended.  (The generated
  634. code pushes each operand onto the stack, then does all the adds.
  635. It's smarter to push and add them one at a time.)
  636.    This makes it a real pain translating numerical routines from
  637. Fortran, especially since constants are taken to be of type
  638. extended.
  639.    The bug was fixed in 5.5.
  640.  
  641.  A3: From: Bengt Oehman (d92bo@efd.lth.se): A difference between
  642. v4.0 and v5.5 is that you can calculate constants in tp55, but not
  643. in 4.0. I see this as a big advantage. For example:
  644.   CONST MaxW = 10;
  645.         MaxH = 20;
  646.         MaxSize = MaxW*MaxH;
  647.         { or }
  648.         MaxX = 100;
  649.         HalfMaxX = MaxX DIV 2;
  650. cannot be compiled with 4.0.
  651. --------------------------------------------------------------------
  652.  
  653. From ts@uwasa.fi Sat Sep 14 00:00:09 1996
  654. Subject: Shelling from a TP program
  655.  
  656. 9. *****
  657.  Q: How do I execute an MS-DOS command from within a TP program?
  658.  
  659.  A: The best way to answer this question is to give an example.
  660.      {$M 2048, 0, 0}   (* <-- Important *)
  661.      program outside;
  662.      uses dos;
  663.      begin
  664.        write ('Directory call from within TP by Timo Salmi');
  665.        SwapVectors;
  666.        Exec (GetEnv('comspec'), '/c dir *.*');  (* Execution *)
  667.        SwapVectors;
  668.        (* Testing for errors is recommended *)
  669.        if DosError <> 0 then
  670.          writeln ('Dos error number ', DosError)
  671.        else
  672.          writeln ('Mission accomplished, exit code ', DosExitCode);
  673.        (* For DosError and DosExitCode details see the TP manual *)
  674.      end.
  675. Alternatively, take a look at execdemo.pas from demos.arc which
  676. should be on the disk accompanying Turbo Pascal.
  677.    What the above Exec does is that it executes the command
  678. processor. The /c specifies that the command interpreter is to
  679. perform the command, and then stop (not halt).
  680.    I have also seen it asked how one can swap the Turbo Pascal
  681. program to the disk when shelling. It is unnecessary to program that
  682. separately because there is an excellent program to do that for you.
  683. It is ftp://garbo.uwasa.fi/pc/sysutil/shrom24b.zip. Also of interest
  684. to advanced programmers even if in C
  685.  107534 Dec 12 1992 ftp://garbo.uwasa.fi/pc/c-lang/spwno413.zip
  686.  spwno413.zip Disk/XMS Swapping replacement for spawn(), w/C, R.Brown
  687.   Somewhat surprisingly some users have had difficulties with
  688. redirecting shelled output. It is straight-forward. In the above
  689. code one would use, for example
  690.   Exec (GetEnv('comspec'), '/c dir *.* > tmp');
  691. --------------------------------------------------------------------
  692.  
  693. From ts@uwasa.fi Sat Sep 14 00:00:10 1996
  694. Subject: Millisecond timing
  695.  
  696. 10. *****
  697.  Q: How is millisecond timing done?
  698.  
  699.  A: A difficult task, but the facilities are readily available.
  700. TurboPower Software's commercial Turbo Professional (don't confuse
  701. with Borland's Turbo Professional) has a unit for this. (The usual
  702. disclaimer applies). It is called tptimer and is part of the
  703. ftp://garbo.uwasa.fi/pc/turbopas/bonus507.zip package. This one has
  704. been released to the PD. I have also seen a SimTel upload
  705. announcement of a ztimer11.zip for C and ASM, but I have no further
  706. information on that. ftp://garbo.uwasa.fi/pc/turbopas/qwktimer.zip
  707. is another option. It is not quite as accurate as tptimer.
  708.    To test the tptimer unit in bonus507.zip you can use the
  709. following example code
  710.   uses Crt, tptimer;
  711.   var time1, time2 : longint;
  712.   begin
  713.     InitializeTimer;
  714.     time1 := ReadTimer;
  715.     Delay (1356);    (* Or whatever code you wish to benchmark *)
  716.     time2 := ReadTimer;
  717.     RestoreTimer;
  718.     writeln ('Elapsed = ', ElapsedTime (time1, time2)/1000.0 : 0 : 3);
  719.   end.
  720.    It is quite another question when you really need the millisecond
  721. timing. The most common purpose for millisecond timing is testing
  722. the efficiency of alternative procedures and functions, right? The
  723. way I compare mine is simple. I call the procedures or functions I
  724. want to compare for speed, say, a thousand times in a loop.  And
  725. test this for elapsed time. This way the normal resolution (18.2
  726. cycles per second) of the system clock becomes sufficient. This is
  727. accurate enough for the comparisons.
  728.      var elapsed : real; i : word;
  729.      elapsed := TIMERFN;  (* e.g. from /pc/ts/tspa3555.zip *)
  730.      for i := 1 to 1000 do YOURTEST;  (* Try out the alternatives *)
  731.      elapsed := TIMERFN - elapsed;
  732.      writeln ('Elapsed : ', elapsed : 0 : 2);
  733. Incidentally, if you want to make more elaborate evaluations of the
  734. efficiency of your code, Borland's Turbo Profiler is a useful tool.
  735. (The usual disclaimer naturally applies.)
  736. --------------------------------------------------------------------
  737.  
  738. From ts@uwasa.fi Sat Sep 14 00:00:11 1996
  739. Subject: Text font customizing
  740.  
  741. 11. *****
  742.  Q: How can I customize the text characters to my own liking?
  743.  
  744.  A: As far as I know, text-mode characters are hard-coded, and
  745. cannot be customized at all unless you have an EGA or VGA adapter.
  746. But you can always retrieve the bitmap information for the ascii
  747. characters from your PC.
  748.    The bitmap table for the lower part of the character set (0-127)
  749. starts at memory position $F000 and ends at $FA6E. The upper part is
  750. not at a fixed memory location. The pointer to the memory address of
  751. upper part of the ascii table (provided that graftabl has been
  752. loaded) is at an address $007C. One way of saying this is that the
  753. segment address of the upper part's memory location is at $007E, and
  754. its offset at $007C.
  755.    Going into more details is beyond the scope of this posting. If
  756. you want more information see Michael Tischer (1992), PC Intern
  757. System Programming, "Selecting and Programming Fonts", pp. 197-210.
  758. It also has information on a remotely related task of using sprites
  759. (pp. 305-373), a concept familiar from the days of the Commodore 64
  760. games programming. For another reference to customizing characters
  761. see Kent Porter (1987), Stretching Turbo Pascal, Chapter 12, and
  762. Kent Porter & Mike Floyd (1990), Stretching Turbo Pascal. Version
  763. 5.5. Revised Edition. Brady, Chapter 11.
  764.    If you are interested in a demonstration of utilizing the
  765. bitmapped character information (no source code available), take a
  766. look at the demo in the garbo.uwasa.fi anonymous FTP archives file
  767. ftp://garbo.uwasa.fi/pc/ts/tsdemo16.zip (or whatever version number
  768. is current).
  769.    Turbo Pascal also supports what is called stroked fonts (the
  770. .chr) files which draw characters instead of bitmapping them. The
  771. user should be able to write one's own .chr definitions, but I have
  772. no experience nor information on how this can be done.
  773.    There is something called bgikit10.zip which has facilities for
  774. making fonts and adding graphics drivers. The problem is that I
  775. cannot make it publicly available, since I think that it is not PD.
  776. I am still missing the information. Unfortunately, it is not even
  777. the only case where I encountered the fact that Borland does not
  778. seem at all interested in the UseNet users' queries about the status
  779. and distributability of their material.
  780.    (From Leonard Erickson Leonard.Erickson@f51.n105.z1.fidonet.org
  781. Well, you can *also* do it if you have a Hercules Graphics Card Plus
  782. or Hercules InColor card (as far as I know, the only cards that
  783. implemented Hercules RamFont 'standard'). And you can modify the
  784. upper 128 characters on a CGA card. BTW, the RamFont cards are
  785. *nice* pity it appeared too late to become a standard. It's a *lot*
  786. more flexible than EGA/VGA fonts (I can have several *dozen* fonts
  787. resident).)
  788. --------------------------------------------------------------------
  789.  
  790. From ts@uwasa.fi Sat Sep 14 00:00:12 1996
  791. Subject: Finding files in TP
  792.  
  793. 12. *****
  794.  Q: How to find the files in a directory AND subdirectories?
  795.  
  796.  A: Writing a program that goes through the files of the directory,
  797. and all the subdirectories below it, is based on Turbo Pascal's file
  798. finding commands and recursion. This is universal whether you are
  799. writing, for example, a directory listing program, or a program that
  800. deletes, say, all the .bak files, or some other similar task.
  801.    To find (for listing or other purposes) the files in a directory
  802. you need above all the FindFirst and FindNext keywords, and testing
  803. the predefined file attributes. You make these a procedure, and call
  804. it recursively. If you want good examples with source code, please
  805. see PC World, April 1989, p. 154; Kent Porter & Mike Floyd (1990),
  806. Stretching Turbo Pascal. Version 5.5. Revised Edition, Chapter 23;
  807. Michael Yester (1989), Using Turbo Pascal, p. 437; Michael Tischer
  808. (1992), PC Intern System Programming, pp. 796-798.
  809.    The simple (non-recursive) example listing all the read-only
  810. files in the current directory shows the rudiments of the principle
  811. of Using FindFirst, FindNext, and the file attributes, because some
  812. users find it hard to use these keywords. Also see the code in the
  813. item "How to establish if a name refers to a directory or not?" of
  814. this same FAQ collection you are now reading.
  815.     uses Dos;
  816.     var FileInfo : SearchRec;
  817.     begin
  818.       FindFirst ('*.*', AnyFile, FileInfo);
  819.       while DosError = 0 do
  820.         begin
  821.           if (FileInfo.Attr and ReadOnly) > 0 then
  822.             writeln (FileInfo.Name);
  823.           FindNext (FileInfo);
  824.         end;
  825.     end.  (* test *)
  826.  
  827.  A2: While we are on the subject related to FindFirst and FindNext,
  828. here are two useful examples:
  829.  
  830. (* Number of files in a directory (not counting directories) *)
  831. function DFILESFN (dirName : string) : word;
  832. var nberOfFiles  : word;
  833.     FileInfo     : searchRec;
  834. begin
  835.   if dirName[Length(dirName)] <> '\' then dirName := dirName + '\';
  836.   dirName := dirName + '*.*';
  837.   {}
  838.   nberOfFiles := 0;
  839.   FindFirst (dirName, AnyFile, FileInfo);
  840.   while DosError = 0 do
  841.     begin
  842.       if ((FileInfo.Attr and VolumeId) = 0) then
  843.         if (FileInfo.Attr and Directory) = 0 then
  844.           Inc (nberOfFiles);
  845.       FindNext (FileInfo);
  846.     end; {while}
  847.   dfilesfn := nberOfFiles;
  848. end;  (* dfilesfn *)
  849.  
  850. (* Number of immediate subdirectories in a directory *)
  851. function DDIRSFN (dirName : string) : word;
  852. var nberOfDirs : word;
  853.     FileInfo    : searchRec;
  854. begin
  855.   if dirName[Length(dirName)] <> '\' then dirName := dirName + '\';
  856.   dirName := dirName + '*.*';
  857.   {}
  858.   nberOfDirs:= 0;
  859.   FindFirst (dirName, AnyFile, FileInfo);
  860.   while DosError = 0 do
  861.     begin
  862.       if ((FileInfo.Attr and VolumeId) = 0) then
  863.         if (FileInfo.Attr and Directory) > 0 then
  864.           if (FileInfo.Name <> '.') and (FileInfo.Name <> '..') then
  865.             Inc (nberOfDirs);
  866.       FindNext (FileInfo);
  867.     end; {while}
  868.   ddirsfn := nberOfDirs;
  869. end;  (* ddirsfn *)
  870. --------------------------------------------------------------------
  871.  
  872. From ts@uwasa.fi Sat Sep 14 00:00:13 1996
  873. Subject: A generic power function code for TP
  874.  
  875. 13. *****
  876.  Q: I need a power function but there is none in Turbo Pascal.
  877.  
  878.  A: Pascals do not have an inbuilt power function. You have to write
  879. one yourself. The common, but non-general method is defining
  880.    function POWERFN (number, exponent : real) : real;
  881.      begin
  882.        powerfn := Exp(exponent*Ln(number));
  883.      end;
  884. To make it general use:
  885.    (* Generalized power function by Prof. Timo Salmi *)
  886.    function GENPOWFN (number, exponent : real) : real;
  887.    begin
  888.      if (exponent = 0.0) then
  889.        genpowfn := 1.0
  890.      else if number = 0.0 then
  891.        genpowfn := 0.0
  892.      else if abs(exponent*Ln(abs(number))) > 87.498 then
  893.        begin writeln ('Overflow in GENPOWFN expression'); halt; end
  894.      else if number > 0.0 then
  895.        genpowfn := Exp(exponent*Ln(number))
  896.      else if (number < 0.0) and (Frac(exponent) = 0.0) then
  897.        if Odd(Round(exponent)) then
  898.          genpowfn := -GENPOWFN (-number, exponent)
  899.        else
  900.          genpowfn :=  GENPOWFN (-number, exponent)
  901.      else
  902.        begin writeln ('Invalid GENPOWFN expression'); halt; end;
  903.    end;  (* genpowfn *)
  904. On the lighter side of things an extract from an answer of mine in
  905. the late comp.lang.pascal UseNet newsgroup:
  906.  >anyone point out why X**Y is not allowed in Turbo Pascal?
  907.    The situation in TP is a left-over from standard
  908.    Pascal. You'll recall that Pascal was originally
  909.    devised for teaching programming, not for
  910.    something as silly and frivolous as actually
  911.    writing programs.  :-)
  912. --------------------------------------------------------------------
  913.  
  914. From ts@uwasa.fi Sat Sep 14 00:00:14 1996
  915. Subject: Arrays > 64K
  916.  
  917. 14. *****
  918.  Q: How can I create arrays that are larger than 64 kilobytes?
  919.  
  920.  A: Turbo Pascal does not directly support the so-called huge arrays
  921. but you can get by this problem with a clever use of pointers as
  922. presented in Kent Porter, "Handling Huge Arrays", Dr.Dobb's Journal,
  923. March 1988. In this method you point to an element of a two
  924. dimensional array using a^[row].col^[column]. The idea involves too
  925. much code and explanation to be repeated here, so you'll have to see
  926. the original reference. But I know from my own experience, that the
  927. code works like magic. (The code is available from garbo.uwasa.fi
  928. archives as ftp://garbo.uwasa.fi/pc/turbopas/ddj8803.zip). Kent
  929. Porter, "Huge Arrays Revisited", Dr.Dobb's Journal, October 1988,
  930. presents the extension of the idea to huge virtual arrays. (Virtual
  931. arrays mean arrays that utilize disk space).
  932.    Another possibility is using TurboPower Software's (the usual
  933. disclaimer applies) commercial Turbo Professional (don't confuse
  934. with Borland's Turbo Professional) package. It has facilities for
  935. huge arrays, but they involve much more overhead than Kent Porter's
  936. excellent method.
  937.  
  938. (* =================================================================
  939.    My code below is based on a UseNet posting in the late
  940.    comp.lang.pascal by Naji Mouawad nmouawad@watmath.waterloo.edu.
  941.    Naji's idea was for a vector, my adaptation is for a
  942.    two-dimensional matrix. The realization of the idea is simpler
  943.    than the one presented by Kent Porter in Dr.Dobb's Journal, March
  944.    1988. (Is something wrong, this is experimental.)
  945.    ================================================================= *)
  946.    {}
  947.    const maxm = 150;
  948.          maxn = 250;
  949.    {}
  950.    type BigVectorType = array [1..maxn] of real;
  951.         BigMatrixType = array [1..maxm] of ^BigVectorType;
  952.    {}
  953.    var BigAPtr : BigMatrixType;
  954.    {}
  955.    (* Create the dynamic variables *)
  956.    procedure MAKEBIG;
  957.    var i          : word;
  958.        heapNeeded : longint;
  959.    begin
  960.      heapNeeded := maxm * maxn * SizeOf(real) + maxm * 4 + 8196;
  961.      if (MaxAvail <= heapNeeded) then
  962.        begin writeln ('Out of memory'); halt; end;
  963.      for i := 1 to maxm do New (BigAPtr[i]);
  964.    end;  (* makebig *)
  965.    {}
  966.    (* Test that it works *)
  967.    procedure TEST;
  968.    var i, j : word;
  969.    begin
  970.      for i := 1 to maxm do
  971.        for j := 1 to maxn do
  972.          BigAPtr[i]^[j] := i * j;
  973.      {}
  974.      writeln (BigAPtr[5]^[7] : 0:0);
  975.      writeln (BigAPtr[maxm]^[maxn] : 0:0);
  976.    end;  (* test *)
  977.    {}
  978.    (* The main program *)
  979.    begin
  980.      writeln ('Big arrays test by Prof. Timo Salmi, Vaasa, Finland');
  981.      writeln;
  982.      MAKEBIG;
  983.      TEST;
  984.    end.
  985. (For a better test of the heap than in MAKEBIG see Swan (1989), pp.
  986. 462-463.)
  987. --------------------------------------------------------------------
  988.  
  989. From ts@uwasa.fi Sat Sep 14 00:00:15 1996
  990. Subject: Testing printer status
  991.  
  992. 15. *****
  993.  Q: How can I test that the printer is ready?
  994.  
  995.  A: Strictly speaking there is no guaranteed way to detect the
  996. printer status on a PC. As Brian Key Brian@fantasia.demon.co.uk
  997. wrote "Any book dealing with the PC BIOS support of a printer will
  998. quickly show you that there is no hardware definition which deals
  999. with the printer power status.  It simply wasn't designed (and I use
  1000. the word loosely!) into the IBM hardware specs."
  1001.  
  1002.    The usually advocated method in Turbo Pascal is to test the
  1003. status of regs.ah after a call to interrupt 17 Hex (the parallel
  1004. port driver interrupt), service 02:
  1005.       regs.dx := PrinterNumber;  (* LPT1 = 0 *)
  1006.       regs.ah := $02;            (* var regs : registers, uses DOS *)
  1007.       Intr ($17,regs);           (* Interrupt 17 Hex *)
  1008.       status := regs.ah          (* var status : byte *)
  1009. But this is not a good method since the combinations of the status
  1010. bits which indicate a ready state can vary from printer to printer
  1011. and PC to PC. If you want a list of the status bits, see e.g. Ray
  1012. Duncan (1988), Advanced MS-DOS Programming, p. 587. For an example
  1013. of a code using interrupt 17 Hex see Douglas Stivison (1986), Turbo
  1014. Pascal Library, pp. 118-120. Also see Michael Yester (1989), Using
  1015. Turbo Pascal, pp. 494-495.
  1016.    The more generic alternative is to try to write a #13 to the
  1017. printer having the i/o checking off, that is, while {$I-} is in
  1018. effect, and testing the IOResult. But then you must first alter the
  1019. printer retry times default (and restore it afterwards). Else the
  1020. method can take up to a minute instead of an immediate response.
  1021. Also, you must have set the FileMode for LPT1 appropriately (and
  1022. restore it afterwards). Sounds a bit complicated, but you don't have
  1023. to do all this yourself. There is a boolean function "LPTONLFN Get
  1024. the online status of the first parallel printer" for this purpose in
  1025. my ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip (or whatever version
  1026. number is the latest) Turbo Pascal units collection available by
  1027. anonymous FTP or mail server from garbo.uwasa.fi.
  1028.  
  1029.  A2: One potential, somewhat advanced solution is to use the Device
  1030. Driver Control (IOCTL) information. Here is the code.
  1031.   uses Dos;
  1032.   function PRNSTAFN : boolean;
  1033.   var regs   : registers;
  1034.       handle : ^word;
  1035.       f      : file;
  1036.   begin
  1037.     prnstafn := false;
  1038.     if swap(Dosversion) < $0200 then exit;  { At least MS-DOS 2.0 }
  1039.     Assign (f, 'prn');                 { Printer }
  1040.     Reset (f);
  1041.     FillChar (regs, SizeOf(regs), 0);  { Just to make sure }
  1042.     regs.ah := $44;                    { Function $44 }
  1043.     regs.al := $07;                    { Subfunction $07 }
  1044.     handle  := @f;                     { Establish a file handle }
  1045.     regs.bx := handle^;
  1046.     Msdos (regs);                      { Call interrupt $21 }
  1047.     Close (f);
  1048.     if regs.flags and FCarry <> 0 then exit;  { Is the carry flag set? }
  1049.     if regs.al <> $FF then exit;       { regs.al = $FF signals success}
  1050.     prnstafn := true;
  1051.   end;  (* prnstafn *)
  1052.   {}
  1053.   begin
  1054.     if PRNSTAFN then writeln ('Printer ready')
  1055.       else writeln ('Printer not ready');
  1056.     readln;
  1057.   end.
  1058.  
  1059.  A3: Another advanced method is using ports. This solution is based
  1060. on a posting by Joerg Kunze joerg@ang-physik.uni-kiel.de. A warning.
  1061. Do not experiment with the port parameters unless you know exactly
  1062. what you are doing. A serious loss of data might follow.
  1063.   function PRNON : boolean;
  1064.   var dr : word absolute $40:$08;
  1065.   begin
  1066.     prnon := port[dr+1] and $18=$18;
  1067.   end;
  1068. --------------------------------------------------------------------
  1069.  
  1070. From ts@uwasa.fi Sat Sep 14 00:00:16 1996
  1071. Subject: Clearing the keyboard buffer
  1072.  
  1073. 16. *****
  1074.  Q: How can I clear the keyboard type-ahead buffer?
  1075.  
  1076.  A: Three methods are usually suggested for solving this problem.
  1077. a) The first is to use something like
  1078.      uses Crt;
  1079.      while KeyPressed do ReadKey;
  1080. This kludge-type method has the disadvantage of requiring the Crt
  1081. unit. Also, in connection with procedures relying on ReadKey for
  1082. input, it may cause havoc on the programs logic.
  1083. b) The second method accesses directly the circular keyboard buffer
  1084.      var head : word absolute $0040:$001A;
  1085.          tail : word absolute $0040:$001C;
  1086.      procedure FLUSHKB; begin head := tail; end;
  1087. For a slightly different formulation of the same method see Michael
  1088. Tischer (1992), PC Intern System Programming, p. 462.
  1089. c) The third method is to call interrupt 21Hex (the MS-DOS
  1090. interrupt) with the ax register set as $0C00. This method has the
  1091. advantage of not being "hard-coded" like the second method, and thus
  1092. should be less prone to incompatibility.
  1093. --------------------------------------------------------------------
  1094.  
  1095. From ts@uwasa.fi Sat Sep 14 00:00:17 1996
  1096. Subject: Utilizing expanded memory
  1097.  
  1098. 17. *****
  1099.  Q: How can I utilize expanded memory (EMS) in my programs?
  1100.  
  1101.  A: I have no experience (yet?) on this subject myself, but I can
  1102. give you a list of references: Michael Tischer (1990), Turbo Pascal
  1103. Internals, Abacus, Chapter 9; Michael Tischer (1992), PC Intern
  1104. System Programming, Chapter 12; Stephen O'Brien (1988), Turbo
  1105. Pascal, Advanced Programmer's Guide, Borland-Osborne, Chapter 4;
  1106. Chris Ohlsen & Gary Stoker (1989), Turbo Pascal Advanced Techniques,
  1107. Que, Chapter 11, Robert Jourdain (1992), Programmer's Problem
  1108. Solver, 2nd ed., Brady Publishing, pp. 68-87, and, maybe most
  1109. importantly, Dorfman & Neuberger, Turbo Pascal Memory Management
  1110. Techniques (with lots of code).
  1111.    Furthermore, Turbo Pascal delivery disks (at least 5.0) contain a
  1112. demos.arc archive which includes an ems.pas file.
  1113. --------------------------------------------------------------------
  1114.  
  1115. From ts@uwasa.fi Sat Sep 14 00:00:18 1996
  1116. Subject: Capturing the entire command line
  1117.  
  1118. 18. *****
  1119.  Q: How can I obtain the entire command line (spaces and all)?
  1120.  
  1121.  A: ParamCount and ParamStr are for parsed parts of the command line
  1122. and cannot be used to get the command line exactly as it was. See
  1123. what happens if you try to capture
  1124.   "Hello.   I'm here"
  1125. you'll end up with a false number of blanks. For obtaining the
  1126. command line unaltered use
  1127.   type CommandLineType = string[127];
  1128.   var  CommandLinePtr  : ^CommandLineType;
  1129.   begin
  1130.     CommandLinePtr := Ptr(PrefixSeg, $80);
  1131.     writeln (CommandLinePtr^);
  1132.   end;
  1133. A warning. If you want to get this correct (the same goes for TP's
  1134. own ParamStr and ParamCount) apply them early in your program. At
  1135. least they must be used before any disk I/O takes place!
  1136. :
  1137. A related example demonstrating a function giving the number of
  1138. characters on the command line
  1139.   function CMDNBRFN : byte;
  1140.   var paramPtr : ^byte;
  1141.   begin
  1142.     paramPtr := Ptr (PrefixSeg, $80);
  1143.     cmdnbrfn := paramPtr^
  1144.   end;  (* cmdnbrfn *)
  1145. For the contents of the Program Segment Prefix (PSP) see Tischer,
  1146. Michael (1992), PC Intern System Programming, p. 753.
  1147. --------------------------------------------------------------------
  1148.  
  1149. From ts@uwasa.fi Sat Sep 14 00:00:19 1996
  1150. Subject: Redirecting from printer to file
  1151.  
  1152. 19. *****
  1153.  Q: How do I redirect text from printer to file in my TP program?
  1154.  
  1155.  A: Simple. This is done in Turbo Pascal by using the assign command
  1156. (think what the word 'assign' implies). Here is a simple example of
  1157. the idea.
  1158.   uses Printer;
  1159.   begin
  1160.     assign (lst, 'printer.log');
  1161.     rewrite (lst);
  1162.     writeln (lst, 'Hello world');
  1163.     close (lst);
  1164.   end.
  1165. --------------------------------------------------------------------
  1166.  
  1167. From ts@uwasa.fi Sat Sep 14 00:00:20 1996
  1168. Subject: Turbo Pascal users are just wimps
  1169.  
  1170. 20. *****
  1171.  Q: Turbo Pascal is for wimps. Why don't you use standard Pascal or
  1172. better still why don't you use C?
  1173.  
  1174.  A: These kinds of "real-programmers" statements often reflect what
  1175. is called self-over-others attitude, and they are a part of a kind
  1176. of a programming lore or cult. Basically, these attitudes waive the
  1177. simple fact that one should select one's tools according to the task
  1178. at hand, not vice versa. On the other hand one's productivity is
  1179. usually best when being able to use tools which one is familiar and
  1180. comfortable with. (Note however that the real-programmer's lore is
  1181. not really interested in producing results.)
  1182.    In very rough terms there are two attitudes to programming
  1183. languages. They can be seen as tools for writing applications, or
  1184. (by surprisingly many) as ends themselves.
  1185.    If we first look at standard Pascal (versus Turbo Pascal),
  1186. considering the language primary and its usage secondary is common.
  1187. This results from the history of Pascal, since as we all know it was
  1188. originally meant as a means for teaching programming concepts, not
  1189. at all for writing applications. But because Pascal turned out to be
  1190. useful also for writing applications, it has been extended for some
  1191. operating systems, most notably MS-DOS (Turbo Pascal) and VAX/VMS
  1192. (VAX Pascal). Both remedy a lot of flaws from the application
  1193. programmer's point of view. Most importantly they have a true file
  1194. I/O interface, and enhanced string handling. Turbo Pascal (the more
  1195. generic of these two) clearly draws from the structure and ideas of
  1196. advanced BASICs (and vice versa). While in standard Pascal the
  1197. language is an end by itself, for Turbo Pascal the only relevant
  1198. issue is its usefulness for writing applications.
  1199.    One problem that one encounters when moving away from standard
  1200. Pascal is the problem of portability. This is a truly serious
  1201. problem, since most often extensive rewriting is necessary from
  1202. converting say Turbo Pascal to, say, Unix Pascal. I have taken Unix
  1203. Pascal as the extreme example, since Unix Pascal is almost nothing
  1204. but the standard Pascal having no useful file I/O.
  1205.    If one considers C, its best aspect from applications point of
  1206. view is portability, and its strength for system programming. But it
  1207. is not an easy language to learn. Proponents of C also often have
  1208. the tendency discussed above, that is seeing the language as
  1209. primary, and its utilization as secondary. Now why this tendency,
  1210. not only for C, but in general? I've had the opportunity of writing
  1211. programs starting from the late 1960's, and one observation I have
  1212. made, and often propounded the view is that it is not writing code
  1213. that is the really difficult part. What is really difficult it is
  1214. coming up with good and original ideas for programs to write. I see
  1215. applications as primary, and the tools as secondary. As to Turbo
  1216. Pascal, I've written in many languages (including Cobol, Fortran,
  1217. several Basics and Pascals, and command languages) and I like Turbo
  1218. Pascal because it is one of the most convenient and flexible tools
  1219. for writing the kind of applications that I usually write and
  1220. distribute for the Public Domain. That is I use Turbo Pascal because
  1221. I'm comfortable with it in writing applications, and have thus
  1222. gathered a very useful modular library for it over the years, not
  1223. because of any inherent value attached to Turbo Pascal per se.
  1224.  
  1225.  A2: Another, a somewhat resembling line is made up by the arguments
  1226. about standards in Pascal which were recycled in the late
  1227. comp.lang.pascal time after time. Very often they end up with
  1228. purists vs pragmatists arguing about the true or imaginary viles of
  1229. using GOTOs. I find all this somewhat futile, although I understand
  1230. the academic nature of the background. As you'll recall, Pascal was
  1231. first developed for academic teaching programming concepts, not for
  1232. any practical programming. That came later, and the ensuing
  1233. popularity of Pascal in practical applications must have come as a
  1234. surprise way back then. I admit being biased in not sympathizing
  1235. with Pascal standard stalwarts. I am far more interested in getting
  1236. the job done than in defending a barren orthodoxy.
  1237.    Since Turbo Pascal version 7.0 introduced the "break" and
  1238. "continue" keywords to handle jumps in loops, GOTOs are much easier
  1239. to avoid without undue complications.
  1240. --------------------------------------------------------------------
  1241.  
  1242. From ts@uwasa.fi Sat Sep 14 00:00:21 1996
  1243. Subject: Turning off the cursor
  1244.  
  1245. 21. *****
  1246.  Q: How do I turn the cursor off?
  1247.  
  1248.  A: The usually advocated trick for turning the cursor off is to
  1249. equate the lower and the upper scan line of the cursor as explained
  1250. e.g. in Stephen O'Brien (1988), Turbo Pascal, Advanced Programmer's
  1251. Guide.
  1252.      uses Dos;
  1253.      var regs : registers;
  1254.      begin
  1255.        regs.ax := $0100;   (* Service $01 *)
  1256.        regs.cl := $20;     (* Top scan line *)
  1257.        regs.ch := $20;     (* Bottom scan line *)
  1258.        Intr ($10, regs);   (* ROM BIOS video driver interrupt *)
  1259.      end;
  1260. To turn the cursor back on this (and many other) sources suggest
  1261. setting regs.ch and regs.cl as 12 and 13 for mono screen, and 6 and
  1262. 7 for others.
  1263.    This is not a good solution since it is equipment dependent, and
  1264. may thus produce unexpected results. Better to store the current
  1265. scan line settings, and turn off the cursor bit. Below is the code
  1266. from ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip (or whatever version
  1267. number is the latest) available by anonymous FTP from garbo.uwasa.fi
  1268. archives. The general idea is that regs.ch bit 5 toggles the cursor
  1269. on / off state. Thus to set the cursor off, apply
  1270.   regs.ch := regs.ch or $20;    (* $20 = 00100000 *)
  1271. and to set it on, apply
  1272.   regs.ch := regs.ch and $DF;   (* $DF = 11011111 *)
  1273. (* From TSUNTE unit, which also has a CURSON procedure *)
  1274. procedure CURSOFF;
  1275. var regs : registers;
  1276. begin
  1277.   FillChar (regs, SizeOf(regs), 0);  (* Initialize, a precaution *)
  1278.   {... find out the current cursor size (regs.ch, regs.cl) ...}
  1279.   regs.ah := $03;
  1280.   regs.bh := $00;    (* page 1, superfluous because of FillChar *)
  1281.   Intr ($10, regs);  (* ROM BIOS video driver interrupt *)
  1282.   {... turn off the cursor without changing its size ...}
  1283.   regs.ah := $01;                   (* Below are bits 76543210 *)
  1284.   regs.ch := regs.ch or $20;  (* Turn on bit 5; $20 = 00100000 *)
  1285.   Intr ($10, regs);
  1286. end;  (* cursoff *)
  1287.  
  1288.  A2: A comment from Leonard Erickson leonard@qiclab.scn.rain.com.
  1289. Reprinted with permission. There's a *reason* those sources don't
  1290. suggest storing the current scan line settings. On IBM Monochrome
  1291. Display Adapters (MDA), Hercules Graphics Cards, and the various
  1292. clones of both, the "read cursor start and end scan lines" function
  1293. *always* returns the same values. And those values are almost never
  1294. the actual settings. Most cards return 6 & 7. Some return 12 & 13.
  1295. But they return these values even if the cursor has been set to
  1296. something else.
  1297.    So you are *still* stuck with checking the hardware type if the
  1298. screen is in mode 7.
  1299.    See the Interrupt list for details on this mess.
  1300.  
  1301.  A3: Another solution that has been suggested is putting the cursor
  1302. outside the screen.  But you can't do this with the Crt's GotoXY
  1303. procedure, since it ignores off screen positions, as observed by
  1304. Luiz Marques luiz.marques%mandic@ibase.org.br. You'll need to use
  1305. video interrupt, that is $10, function $02. Fair enough, but
  1306. somewhat complicated. Besides, how do you write on the screen if the
  1307. cursor position is off it?
  1308.  
  1309.  A4: This snippet of disabling the cursor at hardware level was
  1310. posted to comp.lang.pascal (now news:comp.lang.pascal.borland) by
  1311. JAB@ib.rl.ac.uk. Corrections due to John Stockton. John also points
  1312. out that this probably needs a VGA to work.
  1313.   procedure turn_off_cursor;
  1314.   var num : word;
  1315.   begin
  1316.     port[$03D4]:=$0A; num:=port[$03D5];
  1317.     port[$03D4]:=$0A; port[$03D5]:=num or 32;
  1318.   end;
  1319.   {}
  1320.   procedure turn_on_cursor;
  1321.   var num : word;
  1322.   begin
  1323.     port[$03D4]:=$0A; num:=port[$03D5];
  1324.     port[$03D4]:=$0A; port[$03D5]:=num and not 32;
  1325.   end;
  1326.   {}
  1327.   procedure toggle_cursor;
  1328.   var num : word;
  1329.   begin
  1330.     port[$03D4]:=$0A; num:=port[$03D5];
  1331.     port[$03D4]:=$0A; port[$03D5]:=num xor 32;
  1332.   end;
  1333.  
  1334.  A5: (Not to be taken seriously). Simple, turn off your computer and
  1335. the cursor stops showing :-).
  1336. --------------------------------------------------------------------
  1337.  
  1338. From ts@uwasa.fi Sat Sep 14 00:00:22 1996
  1339. Subject: Finding the roots of a polynomial
  1340.  
  1341. 22. *****
  1342.  Q: How to find all roots of a polynomial?
  1343.  
  1344.  A: If you need the code, see Turbo Pascal Numerical Toolbox and/or
  1345. Press & Flannery & Teukolsky & Vetterling (1986), Numerical Recipes,
  1346. The Art of Scientific Computing, Cambridge University Press. The
  1347. Numerical Recipes codes are available as /pc/turbopas/nrpas13.zip
  1348. (big, 404k!). If you just need to solve such a task (without code
  1349. available), get ftp://garbo.uwasa.fi/pc/ts/tsnum13.zip (or whatever
  1350. version number is the latest) from garbo.uwasa.fi archives by
  1351. anonymous FTP or mail server.
  1352. --------------------------------------------------------------------
  1353.  
  1354. From ts@uwasa.fi Sat Sep 14 00:00:23 1996
  1355. Subject: Pascal homework on the net
  1356.  
  1357. 23. *****
  1358.  Q: What is all this talk about "Pascal homework on the net"?
  1359.  
  1360.  A: This is one of the subjects that seems to pop up at regular
  1361. intervals, cause some heated exchange for awhile, and then die down
  1362. again leaving some users harboring warranted or unwarranted grudges.
  1363.    Some posters to comp.lang.pascal (later comp.lang.pascal.borland)
  1364. have been very concerned of the possibility that the questions posed
  1365. on the net are related to students' homework assignments. I don't
  1366. have any unequivocal answers or a clear-cut stand on this question,
  1367. just some comments.
  1368.    The most important task of a newsgroup like comp.lang.pascal.borland
  1369. is the exchange of information between the users. If you think that
  1370. what you are going to post is interesting and useful to the group,
  1371. that should be your topmost criterion.
  1372.    If it is really a student that wants his/her work done on the net
  1373. (how do we know anyway?) also consider the following fact. Being
  1374. able to use a newsgroup amounts to having learned at least something
  1375. about using computers, and that is something per se.
  1376.    Even if the student may short-sightedly not realize it, providing
  1377. ALL the code for a student's homework is detrimental to the student,
  1378. since it is she/he that foregoes understanding what he/she is doing.
  1379. The group should not condone outright cheating. Being (partly) a
  1380. teacher myself, I understand also this view.
  1381.    If a student is stuck with a problem in his/her code, I don't see
  1382. any real harm in helping out, especially if the problem has general
  1383. interest. Instructing is what teaching is about, anyway, isn't it?
  1384.    But, on the other hand, I must admit that I find a it rather
  1385. flagrant if a posting asks for something of the kind "I have to
  1386. complete my term assignment to write a function plotter by the end
  1387. of this month. Send me the code, since I'm too busy with my other
  1388. exams to write it myself" (a true quote).
  1389.    Finally, let's not jump to premature conclusions about anyone's
  1390. questions.  That's what most often triggers off a vicious circle of
  1391. flaming.
  1392. --------------------------------------------------------------------
  1393.  
  1394. From ts@uwasa.fi Sat Sep 14 00:00:24 1996
  1395. Subject: Linking bgi drivers into executables
  1396.  
  1397. 24. *****
  1398.  Q: How can I link graphics drivers directly into my executable?
  1399.  
  1400.  A: This is a complicated, yet a very useful task, because then you
  1401. won't need any separate graphics drivers (or fonts) to go separately
  1402. along with your program. Unfortunately, Turbo Pascal documentation
  1403. on this task is a bit confusing.
  1404.    1) The very first step is to get the necessary files from the
  1405. Turbo Pascal disks to your working directory. To start with, you'll
  1406. need binobj.exe and all the .bgi files.
  1407.    2) Run the following commands (best to place them in a batch,
  1408. call it e.g. makeobj.bat):
  1409.      binobj cga.bgi cga CGADriverProc
  1410.      binobj egavga.bgi egavga EGAVGADriverProc
  1411.      binobj herc.bgi herc HercDriverProc
  1412.      binobj pc3270.bgi pc3270 PC3270DriverProc
  1413.      binobj att.bgi att ATTDriverProc
  1414.      rem binobj ibm8514.bgi 8514 IBM8514DriverProc
  1415.    3) Get drivers.pas from the Turbo Pascal disk and compile it with
  1416. Turbo Pascal. Now you have a drivers.tpu unit which contains all the
  1417. graphics drivers.
  1418.    4) Now you won't need the .bgi and the .obj files any more. You
  1419. may delete them from your working directory.
  1420.    5) Write your graphics program in the usual manner. But before
  1421. putting your program in the graphics mode use the following
  1422. procedure if you want to link e.g. the EGAVGA graphics driver
  1423. directly into your executable. (Link just the driver(s) you'll need,
  1424. since the drivers take up a lot of space.)
  1425.      uses Graph, Drivers;
  1426.      :
  1427.      procedure EGAVGA2EXE;
  1428.      begin
  1429.        if RegisterBGIdriver(@EGAVGADriverProc) < 0 then
  1430.          begin
  1431.            writeln ('EGA/VGA: ', GraphErrorMsg(GraphResult));
  1432.            halt(1);
  1433.          end;
  1434.      end; (* egavga2exe *)
  1435.      :
  1436.    Linking the .bgi and .chr drivers is also covered in Swan (1989),
  1437. Mastering Turbo Pascal 5.5 pp. 355-359 and Mitchell (1993), Borland
  1438. Pascal Developer's Guide , pp. 221-229.
  1439.    If you have Turbo Pascal 7.0 its help function gives you an
  1440. example code. One way of getting at it is the following. In the
  1441. Turbo Pascal IDE (that is in the editor) type RegisterBGIdriver.
  1442. Then place the cursor on it and press alt-F1 for help of that
  1443. keyword. Press alt-F10 and select "Copy example". Press first <ESC>
  1444. then alt-F10 and select Paste. The example code is pasted within
  1445. your program for you to study.
  1446.    Incidentally, although this is a slightly different matter, you
  1447. can link any data material into your executable. See Stephen
  1448. O'Brien, (1988), Turbo Pascal, Advanced Programmer's Guide, pp. 31 -
  1449. 35 for more details.
  1450. --------------------------------------------------------------------
  1451.  
  1452. From ts@uwasa.fi Sat Sep 14 00:00:25 1996
  1453. Subject: Trapping runtime errors
  1454.  
  1455. 25. *****
  1456.  Q: How can I trap a runtime error?
  1457.  
  1458.  A: What you are probably asking for is a method writing a program
  1459. termination routine of your own. To do this, you have to replace
  1460. Turbo Pascal's ExitProc with your own customized exec procedure.
  1461. Several Turbo Pascal text books show ho to do this. See e.g. Tom
  1462. Swan (1989), Mastering Turbo Pascal 5.5, Third edition, Hayden
  1463. Books, pp. 440-454; Michael Yester (1989), Using Turbo Pascal, Que,
  1464. pp. 376-382; Stephen O'Brien (1988), Turbo Pascal, Advanced
  1465. Programmer's Guide, pp. 28-30; Tom Rugg & Phil Feldman (1989), Turbo
  1466. Pascal Programmer's Toolkit, Que, pp. 510-515. Here is an example
  1467.   var OldExitProcAddress : Pointer;
  1468.       x : real;
  1469.   {$F+} procedure MyExitProcedure; {$F-}
  1470.   begin
  1471.     if ErrorAddr <> nil then
  1472.       begin
  1473.         writeln ('Runtime error number ', ExitCode, ' has occurred');
  1474.         writeln ('The error address in decimal is ',
  1475.                   Seg(ErrorAddr^):5,':',Ofs(ErrorAddr^):5);
  1476.         writeln ('That''s all folks, bye bye');
  1477.         ErrorAddr := nil;
  1478.         ExitCode  := 0;
  1479.       end;
  1480.     {... Restore the pointer to the original exit procedure ...}
  1481.     ExitProc := OldExitProcAddress;
  1482.   end;  (* MyExitProcedure *)
  1483.   (* Main *)
  1484.   begin
  1485.     OldExitProcAddress := ExitProc;
  1486.     ExitProc := @MyExitProcedure;
  1487.     x := 7.0; writeln (1.0/x);
  1488.     x := 0.0; writeln (1.0/x);   {The trap}
  1489.     x := 7.0; writeln (4.0/x);   {We won't get this far}
  1490.   end.
  1491. :
  1492. Actually, I utilize this idea in my /pc/ts/tspa3570.zip Turbo Pascal
  1493. units collection, which includes a TSERR.TPU. If you put TSERR in
  1494. your program's uses statement, all the run time errors will be given
  1495. verbally besides the usual, cryptic error number. That's all there
  1496. is to it. That is, the inclusion to the uses statement to your main
  1497. program (if you have the program in several units) is all you have
  1498. to do to enable this handy feature.
  1499. :
  1500. Hans.Siemons@f149.n512.z2.fidonet.org notes "This line:
  1501.     ExitProc := OldExitProcAddress;
  1502. should IMHO never be placed at the end of your exit handler. If for
  1503. one reason or another your own handler should cause a runtime error,
  1504. it would go in an endless loop. If the first statement restores the
  1505. exit chain, this can never happen. I do agree that is not very
  1506. likely that your exit handler produces any runtime error, but it
  1507. performs I/O, and since it is located in a FAQ, people are bound to
  1508. use, and maybe extend it with more tricky stuff."
  1509. --------------------------------------------------------------------
  1510.  
  1511.